/* eslint-disable vue/prop-name-casing */
<template>
  <el-form ref="dataForm" :model="dataForm" label-width="100px">
    <el-row>
      <el-col>
        <el-form-item size="mini" label="审批意见" prop="Name">
          <el-input v-model="dataForm.Suggest" rows="3" type="textarea" :disabled="read" maxlength="259" show-word-limit placeholder="请输入审批意见" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row v-if="!read">
      <el-col style="text-align: right;">
        <el-button size="mini" icon="el-icon-close" type="warning" @click="Reject()">拒绝</el-button>
        <el-button size="mini" icon="el-icon-check" type="primary" @click="Agree()">同意</el-button>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import { gotoNextStep } from '@/api/workflowprocess'
export default {
  // eslint-disable-next-line vue/require-prop-types
  props: ['id', 'suggest'],
  data() {
    return {
      read: false,
      dataForm: {
        Id: '',
        Suggest: '',
        BtnClient: '',
        Parameters: {}
      }
    }
  },
  mounted() {
    if (this.suggest) {
      this.dataForm.Suggest = this.suggest
      this.read = true
    }
  },
  methods: {
    Reject() {
      this.dataForm.Id = this.id
      this.dataForm.BtnClient = 'Reject'
      this.dataForm.Parameters.Suggest = this.dataForm.Suggest
      gotoNextStep(this.dataForm).then((data) => {
        if (data && data.code === '20000') {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.$emit('close')
            }
          })
        } else {
          this.$message.error(data.message)
        }
      })
    },
    Agree() {
      debugger
      this.dataForm.Id = this.id
      this.dataForm.BtnClient = 'Agree'
      this.dataForm.Parameters.Suggest = this.dataForm.Suggest
      gotoNextStep(this.dataForm).then((data) => {
        if (data && data.code === '20000') {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.$emit('close')
            }
          })
        } else {
          this.$message.error(data.message)
        }
      })
    }
  }
}
</script>
